package com.spring.cloud.controller;

import com.spring.cloud.entity.Week01;
import com.spring.cloud.service.Week01Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * Created by qpx on 2018/4/12.
 */
@RestController
@RequestMapping("/springBoot/week")
public class HelloWorldController {

    @Autowired
    Week01Service week01Service;

    @RequestMapping(method = RequestMethod.GET)
    public Week01 queryWeekByID(@RequestParam(name = "abc") Integer weekID) {
        Week01 byId = week01Service.findById(weekID);
        //200
        return byId;
    }

    /**
     * 新增
     *
     * @param week01
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<Week01> saveWeek(Week01 week01) throws Exception {
        week01Service.insertSelective(week01);
        //201
        return new ResponseEntity<Week01>(week01, HttpStatus.CREATED);
    }

    /**
     * 修改
     *
     * @param week01
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT)
    public ResponseEntity<Week01> updateWeek(@RequestBody Week01 week01) {
        week01Service.updateByPrimaryKeySelective(week01);
        //204
        return new ResponseEntity<Week01>(week01, HttpStatus.NO_CONTENT);
    }

    @RequestMapping(method = RequestMethod.DELETE)
    public ResponseEntity<Week01> deleteWeek(Week01 week01) {
        week01Service.deleteByPrimaryKey(week01.getId());
        //204
        return new ResponseEntity<Week01>(week01, HttpStatus.NO_CONTENT);
    }
}
